//
//  SHRollimgeViewController.m
//  UI_CarHome
//
//  Created by dllo on 15/11/4.
//  Copyright (c) 2015年 沈浩. All rights reserved.
//

#import "SHRollimgeViewController.h"
#import "SHHandle.h"
#import "UMSocial.h"
@interface SHRollimgeViewController ()
@property(nonatomic, retain)UIImageView *imageView;
@property(nonatomic, retain)UISwipeGestureRecognizer *leftSwipe;
@property(nonatomic, retain)UISwipeGestureRecognizer *rightSwipe;
@property(nonatomic, retain)UILabel *countLabel;
@end

@implementation SHRollimgeViewController

- (void)dealloc
{
    [_countLabel release];
    [_rightSwipe release];
    [_leftSwipe release];
    [_phoArr release];
    [_imageView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.navigationController.navigationBar.translucent = YES;
    self.view.backgroundColor = [UIColor blackColor];
    [self createImageView];
//    self.countLabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 450, 50, 20)];
//    [self.view addSubview:self.countLabel];
//    [_countLabel release];
//    self.countLabel.text = [NSString stringWithFormat:@"%ld/%ld", self.index + 1, self.phoArr.count];
//    self.countLabel.textColor = [UIColor whiteColor];
//    self.countLabel.textAlignment = NSTextAlignmentRight;
//
     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"分享" style:UIBarButtonItemStylePlain target:self action:@selector(share:)];
}
- (void)share:(UIBarButtonItem *)button {
    NSArray *shareArr = [NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren, nil];
    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.shareIamge]]];
    [UMSocialSnsService presentSnsIconSheetView:self appKey:@"563c383667e58e4ed7000fba" shareText:self.webStr shareImage:image shareToSnsNames:shareArr delegate:nil];

}

- (void)createImageView {
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 150, WIDTH, 300)];
    [self.view addSubview:self.imageView];
    self.imageView.backgroundColor = NEWBLUE;
    [self loadImage];
    // 打开用户交互
    self.imageView.userInteractionEnabled = YES;
    [self.imageView addGestureRecognizer:self.leftSwipe];
    [self.imageView addGestureRecognizer:self.rightSwipe];
    [_rightSwipe release];
    [_leftSwipe release];
    [_imageView release];
}
#pragma mark --轻扫手势
- (UISwipeGestureRecognizer *)leftSwipe {
    if (!_leftSwipe) {
        self.leftSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeAction:)];
        self.leftSwipe.direction = UISwipeGestureRecognizerDirectionRight;
    }
    return _leftSwipe;
}

- (void)leftSwipeAction:(UISwipeGestureRecognizer *)leftSwipe {
    if (self.index == 0) {
        self.index = self.phoArr.count - 1;
    } else {
        self.index--;
    }
    [self loadImage];
}

- (UISwipeGestureRecognizer *)rightSwipe {
    if (!_rightSwipe) {
        self.rightSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeAction:)];
        self.rightSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
    }
    return _rightSwipe;
}

- (void)rightSwipeAction:(UISwipeGestureRecognizer *)rightSwipe {
    if (self.index == self.phoArr.count - 1) {
        self.index = 0;
    } else {
        self.index ++;
    }
    [self loadImage];
}
#pragma mark --加载图片
- (void)loadImage {
//    [self.imageView sd_setImageWithURL:[NSURL URLWithString:self.phoArr[self.index][@"bigPath"]]];
    if (self.countLabel) {
        [self.countLabel removeFromSuperview];
    }
    self.countLabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 450, 50, 20)];
    [self.view addSubview:self.countLabel];
    [_countLabel release];
    self.countLabel.font = [UIFont systemFontOfSize:12];
    self.countLabel.text = [NSString stringWithFormat:@"%ld/%ld", self.index + 1, self.phoArr.count];
    self.countLabel.textColor = [UIColor whiteColor];
    self.countLabel.textAlignment = NSTextAlignmentRight;
    

    [self.imageView sd_setImageWithURL:[NSURL URLWithString:self.phoArr[self.index][@"bigPath"]] placeholderImage:PLACEPICTURE];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
